import express from "express";
import expressWs from "express-ws";
import { readFileSync } from "fs";
import kcoder from "k-coder";
import { resolve } from "path";
import { Conn } from "./Conn";
import { Game } from "./game/Game";
import { Xlsx } from "./game/cfg/Xlsx";
import { KProto } from "./game/proto/KProto";
import KProtoStruct from "./game/proto/KProtoStruct";

Xlsx.init(kcoder);
Xlsx.load(readFileSync(resolve(__dirname, "../data/data.bin")));
KProto.init(kcoder);
KProto.loadAll(KProtoStruct);

const game = new Game().start();
const port = 888;
const app = express();
app.use(express.static(resolve(__dirname, "../../k-slither/build/public")));
expressWs(app).app.ws("/", (ws) => {
    new Conn(game, ws);
});
app.listen(888, () => {
    console.log(`服务端已启动 http://localhost: ${port}`);
});